package dp.mobile.sbm;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class TabActivity extends Activity  implements OnClickListener {	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//Set family
		mFamily = getIntent().getIntExtra(TabActivity.FAMILY_TAG, TabActivity.HOME_FAMILY);
	}
	
	protected void setTabListener() {
		//Set click listeners
		int[] Clicked = new int[] {  R.id.home_tab1, R.id.home_tab2, R.id.home_tab3, R.id.home_tab4 };
		for (int i = 0; i < Clicked.length; i++) findViewById(Clicked[i]).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		//Skip if not clickable
		if (!v.isClickable()) return;
		
		//Create intent
		Intent NewIntent = null;
		
		//Based on view id
		switch (v.getId()) {
		case R.id.home_tab1:
			NewIntent = new Intent(this, HomeActivity.class);
			NewIntent.putExtra(TabActivity.FAMILY_TAG, mFamily);
			break;
		case R.id.home_tab2:
			NewIntent = new Intent(this, ProfileActivity.class);
			NewIntent.putExtra(TabActivity.FAMILY_TAG, mFamily);
			break;
		case R.id.home_tab3:
			NewIntent = new Intent(this, DBActivity.class);
			NewIntent.putExtra(TabActivity.FAMILY_TAG, mFamily);
			break;
		case R.id.home_tab4:
			NewIntent = new Intent(this, AboutActivity.class);
			NewIntent.putExtra(TabActivity.FAMILY_TAG, mFamily);
			break;
		}
		
		//If intent exist
		if (NewIntent != null) {
			//Set flag and start
			NewIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(NewIntent);
		}
	}
	
	//Family constants
	public final static int 	HOME_FAMILY = 1;
	public final static int 	NEWS_FAMILY = 2;
	public final static String 	FAMILY_TAG	= "Family";
	
	//Stuff
	protected int mFamily;
}